import unittest
import logging
import colorlog
from unittest.mock import Mock, MagicMock, call
from custom_logging import setup_logging
from db_task_module.sqlite3_task import Sqlite3Task
from db.sqllite3_wrapper import DbAccess
from process_engine import Context

setup_logging()

class Test_test1(unittest.TestCase):
    
    def __init__(self, methodName = 'runTest'):
        super().__init__(methodName)
        self._logger = logging.getLogger(__name__)

    def test_Sqlite3_Task(self):
        self._logger.info("start %s", __name__)
        db = DbAccess('LocalDb')
        db.execute = MagicMock()
        db.executemany = MagicMock(return_value = 2)
        db.executescript = MagicMock()
        dic = [(1, "n1", "ad 1", 25000), (1, "n1", "ad 1", 25000)]
        db.fecthone = MagicMock(return_value = (1, 'n1'))
        db.fetchall = MagicMock(return_value = dic)
        task = Sqlite3Task(db)
        task.process(Context())
        db.execute.assert_called()
        db.executemany.assert_called()
        db.executescript.assert_called()
        db.fecthone.assert_not_called()
        db.fetchall.assert_called()
        db.execute.fetchall(call("SELECT id, name, address, salary  from COMPANY;"))
        self._logger.info("end %s", __name__)

if __name__ == '__main__':
    unittest.main()
